﻿using System;
using System.Collections.Generic;
using System.Linq;
using SlamCms.Common;

namespace SlamCms.Data
{
	public static class SqlHelpers
	{
		public static string ToSqlIn<T>(this IEnumerable<T> items, bool? asStrings = null)
		{
			IEnumerable<string> values;
			if ((asStrings.HasValue && asStrings.Value) || (!asStrings.HasValue && typeof(T).In(typeof(string), typeof(char), typeof(Guid))))
				values = items.Select(i => @"'{0}'".F(i));
			else
				values = items.Select(i => @"{0}".F(i));

			return string.Join(@",", values.ToArray());
		}
	}
}
